FROM docker.1ms.run/python:3.10-slim

# 设置标签信息
LABEL maintainer="AI Chatbot Team"
LABEL description="Streaming AI Chatbot with Document Export"
LABEL version="1.0.0"

WORKDIR /usr/src/app

# 配置国内镜像源并安装系统依赖
RUN cp /etc/apt/sources.list /etc/apt/sources.list.backup && \
    echo "# 使用阿里云镜像源" > /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian/ bookworm main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free" >> /etc/apt/sources.list && \
    (apt-get update && apt-get install -y --no-install-recommends \
    pandoc \
    ca-certificates \
    git) || \
    (echo "阿里云源失败，尝试清华源..." && \
    echo "# 使用清华大学镜像源" > /etc/apt/sources.list && \
    echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free" >> /etc/apt/sources.list && \
    echo "deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bookworm-security main contrib non-free" >> /etc/apt/sources.list && \
    apt-get update && apt-get install -y --no-install-recommends \
    pandoc \
    ca-certificates \
    git) || \
    (echo "国内源都失败，恢复官方源..." && \
    cp /etc/apt/sources.list.backup /etc/apt/sources.list && \
    apt-get update && apt-get install -y --no-install-recommends \
    pandoc \
    ca-certificates \
    git) && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.backup

# 复制启动脚本并设置权限
COPY scripts/docker-entrypoint.sh ./
RUN chmod +x docker-entrypoint.sh

# 定义环境变量（可以在运行时覆盖）
ENV OPENAI_BASE_URL="https://api.openai.com/v1"
ENV MODEL_NAME="gpt-3.5-turbo"
ENV MAX_TOKENS="4096"
ENV DOCKER_ENV="true"
# Python源配置（默认为空，使用官方源）
ENV PIP_INDEX_URL=""
ENV PIP_TRUSTED_HOST=""

# 暴露端口
EXPOSE 8000

ENTRYPOINT ["/bin/bash", "./docker-entrypoint.sh"]
